package 对称二叉树;

/**
 * @author: zhengtao
 * @description: 相同的树
 * @version: 1.0
 * @date: 2022/10/29  16:58
 */
public class Demo100 {

    public boolean isSameTree(TreeNode p, TreeNode q) {
        //都不为null
        if(p==null&&q==null){
            return true;
        //一个为null
        }else if(p==null||q==null){
            return false;
        //值不相等
        }else if(p.val!=q.val){
            return false;
        }else {
            return  isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
        }

    }
    /**
     Definition for a binary tree node.
     **/
     public class TreeNode {
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode() {}
         TreeNode(int val) { this.val = val; }
         TreeNode(int val, TreeNode left, TreeNode right) {
             this.val = val;
             this.left = left;
             this.right = right;
         }
     }

}
